﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.IO;
using System.Reflection;
using System.Web.Compilation;
using System.Web.Script.Serialization; 
public class LigerHandler : IHttpHandler
{
    public bool IsReusable
    {
        get { return true; }
    }

  

    public void ProcessRequest(HttpContext context)
    { 
        DoProcessRequest(context);  
    }


    void DoProcessRequest(HttpContext context)
    {
        string path = Path.GetFileNameWithoutExtension(context.Request.PhysicalPath);
        var index = path.LastIndexOf('.');
        if (index == -1)
        {
            context.Response.Write(AjaxResult.CreateError("路径错误"));
            context.Response.End();
            return;
        }
        string typeName = path.Substring(0, index);
        string methodName = path.Substring(index + 1);
        var method = HandlerHelper.GetMethod(typeName, methodName);
        if (method == null)
        {
            context.Response.Write(AjaxResult.CreateError(string.Format("找不到类{0} 方法{1}", typeName, methodName)));
            context.Response.End();
            return;
        }
        var result = method.Invoke(null, HandlerHelper.GetMethodParms(method, context));
        context.Response.Write(result);
        context.Response.End();  
    }
}